<template>
  <el-card style="height: 800px">
    <!--    搜索-->
    <el-form :inline="true">
      <el-form-item>
        <el-input type="text" maxlength="10" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="medium" icon="el-icon-search"
          >搜索</el-button
        >
        <el-button>清空</el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-button type="primary">添加</el-button>
      <el-button type="danger">批量删除</el-button>
    </div>
    <el-table :data="pageList" stripe border class="mt-20" style="width: 960px">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" width="80" label="序号" />
      <el-table-column prop="roleName" label="角色名称" width="525" />
      <el-table-column label="操作" width="300">
        <!--         slot-scope="{row,$index}"-->
        <template>
          <el-button type="info" icon="el-icon-info" size="mini" />
          <el-button type="primary" icon="el-icon-check" size="mini" />
          <el-button type="primary" icon="el-icon-edit" size="mini" />
          <el-button type="danger" icon="el-icon-delete-solid" size="mini" />
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="pageNo"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="limit"
      layout=" prev, pager, next, jumper,->,sizes,total"
      :total="totalPage"
      class="mt-20"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script>
import { mapActions, mapState } from "vuex";

export default {
  name: "UserRoot",
  data: function () {
    return {
      pageNo: 1,
      limit: 5,
      totalPage: 0,
      pageList: [],
    };
  },

  methods: {
    ...mapActions("root", ["getInfo"]),
    handleSizeChange(val) {
      this.limit = val;
      this.getPageInfo();
    },
    handleCurrentChange(val) {
      this.pageNo = val;
      this.getPageInfo();
    },
    async getPageInfo() {
      try {
        await this.getInfo({ page: this.pageNo, limit: this.limit });
        console.log(this.total, this.list);
        this.totalPage = this.total;
        this.pageList = this.list;
      } catch (e) {
        console.log(e);
      }
    },
  },
  computed: {
    ...mapState({
      total: (state) => state.root.total,
      list: (state) => state.root.list,
    }),
  },
  mounted() {
    this.getPageInfo();
  },
};
</script>

<style scoped></style>
